import React, {Component} from "react";
import Config from './config'



export default class Video extends Component {
  constructor(props) {
    super(props);

    let $t = this;

    this.componentDidMount = () => {
      $t.openVideo((new Config()).load());
    };

    window.openVideo = $t.openVideo = ({ cameraId }) => {
      const videoConstraints = !cameraId ? {facingMode:'user'} : {deviceId:{exact:cameraId}};
      navigator.mediaDevices.getUserMedia({
        audio: false,
        video: videoConstraints
      }).then(stream =>{
        $t.video = document.getElementById("my-player");
        $t.video.srcObject = stream;
        $t.video.play();
      })
        .catch((e) => {
          console.log(e);
        })
    };

    this.render = () => (
      <video id="my-player"  style={{width: "100%",height:"300px"}} controls="controls"/>
    )

  }
}
